﻿using System;
using System.Text;
using System.Windows.Forms;
namespace YanZhiwei.DotNet2.Utilities.WinForm
{
    /// <summary>
    ///  CheckBox 帮助类
    /// </summary>
    public static class CheckBoxHelper
    {
        #region 设置CheckBox是否选中，【线程安全】
        /// <summary>
        /// 设置CheckBox是否选中，【线程安全】
        /// </summary>
        /// <param name="ck"></param>
        /// <param name="check"></param>
        public static void SetCheckBoxTF(this CheckBox ck, bool check)
        {
            ck.UIThread((MethodInvoker)delegate
            {
                ck.Checked = check;
            });
        }
        #endregion
        #region  转译checkbox的状态
        /// <summary>
        /// 转译checkbox的状态
        /// </summary>
        /// <param name="checkStateFactory">委托</param>
        /// <param name="checks">CheckBox</param>
        /// <returns>转译后的checkbox的状态</returns>
        public static string TranCheckState(Func<CheckState, string> checkStateFactory, params CheckBox[] checks)
        {
            StringBuilder _builder = new StringBuilder();
            if (checks != null && checks.Length > 0)
            {
                foreach (CheckBox ck in checks)
                {
                    _builder.Append(checkStateFactory(ck.CheckState));
                }
            }
            return _builder.ToString();
        }
        #endregion 
    }
}
